package com.yswy.domain.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Api(tags = "微信投诉记录表")
@TableName(value = "wx_complaint_record")
public class WxComplaintRecord {
    @TableId(type = IdType.AUTO)
    private Long id ;
    @ApiModelProperty("商户订单号")
    private String outTradeNo ;
    @ApiModelProperty("微信支付流水号")
    private String transactionId ;
    @ApiModelProperty("微信支付流水号")
    private String amount ;
    @ApiModelProperty("投诉单对应的投诉单号")
    private String complaintId ;
    @ApiModelProperty("投诉时间")
    private String complaintTime ;
    @ApiModelProperty("投诉详情")
    private String complaintDetail ;
    @ApiModelProperty("被诉商户号")
    private String complaintedMchid ;
    @ApiModelProperty("投诉单状态 PENDING：待处理 PROCESSING：处理中 PROCESSED：已处理完成")
    private String complaintState ;
    @ApiModelProperty("投诉人联系方式")
    private String payerPhone ;
    @ApiModelProperty("投诉人openid")
    private String payerOpenid ;
    @ApiModelProperty("投诉资料列表")
    private String complaintMediaList ;
    @ApiModelProperty("投诉单关联订单信息")
    private String complaintOrderInfo ;
    @ApiModelProperty("投诉单关联服务单信息")
    private String serviceOrderInfo ;
    @ApiModelProperty("投诉单是否已全额退款")
    private String complaintFullRefunded ;
    @ApiModelProperty("是否有待回复的用户留言")
    private String incomingUserResponse ;
    @ApiModelProperty("问题描述")
    private String problemDescription ;
    @ApiModelProperty("用户投诉次数")
    private String userComplaintTimes ;
    @ApiModelProperty("问题类型  REFUND：申请退款 SERVICE_NOT_WORK：服务权益未生效  OTHERS：其他类型 ")
    private String problemType ;
    @ApiModelProperty("申请退款金额")
    private String applyRefundAmount ;
    @ApiModelProperty("用户标签列表")
    private String userTagList ;
    @ApiModelProperty("回调接口状态")
    private String actionType;
    @ApiModelProperty("本地处理返溃")
    private String handleMsg;


    public WxComplaintRecord(JSONObject jsonObject , String actionType){
        this.complaintId = jsonObject.getString("complaint_id");
        this.complaintTime  = jsonObject.getString("complaint_time");
        this.complaintDetail = jsonObject.getString("complaint_detail");
        if (jsonObject.has("complainted_mchid")){
            this.complaintedMchid= jsonObject.getString("complainted_mchid") ;
        }
        if (jsonObject.has("complaint_state")) {
            this.complaintState = jsonObject.getString("complaint_state");
        }
        if (jsonObject.has("payer_phone")) {
            this.payerPhone = jsonObject.getString("payer_phone");
        }
        if (jsonObject.has("payer_openid")) {
            this.payerOpenid = jsonObject.getString("payer_openid");
        }
        if (jsonObject.has("complaint_media_list")) {
            this.complaintMediaList = jsonObject.getString("complaint_media_list");
        }
        if (jsonObject.has("complaint_order_info")) {
            String complaintOrderInfo  = jsonObject.getString("complaint_order_info") ;
            JSONArray jsonArray = JSONArray.fromObject(complaintOrderInfo);
            JSONObject jsonObject1 = jsonArray.getJSONObject(0);
            this.outTradeNo = jsonObject1.getString("out_trade_no") ;
            this.transactionId =  jsonObject1.getString("transaction_id") ;
            this.amount =  jsonObject1.getString("amount") ;
            this.complaintOrderInfo = complaintOrderInfo;
        }
        if (jsonObject.has("service_order_info")) {
            this.serviceOrderInfo = jsonObject.getString("service_order_info");
        }
        if (jsonObject.has("complaint_full_refunded")) {
            this.complaintFullRefunded = jsonObject.getString("complaint_full_refunded");
        }
        if (jsonObject.has("incoming_user_response")) {
            this.incomingUserResponse = jsonObject.getString("incoming_user_response");
        }
        if (jsonObject.has("problem_description")) {
            this.problemDescription = jsonObject.getString("problem_description");
        }
        if (jsonObject.has("user_complaint_times")) {
            this.userComplaintTimes = jsonObject.getString("user_complaint_times");
        }
        if (jsonObject.has("problem_type")) {
            this.problemType = jsonObject.getString("problem_type");
        }
        if (jsonObject.has("apply_refund_amount")) {
            this.applyRefundAmount = jsonObject.getString("apply_refund_amount");
        }
        if (jsonObject.has("user_tag_list")) {
            this.userTagList = jsonObject.getString("user_tag_list");
        }
        this.actionType = actionType;
    }
}
